#-*- coding:gbk -*-
'''
Created on 2012-7-23

@author: m_guidm_guidy
'''

def singleton(cls, *args, **kw):   
    instances = {}   
    def _singleton():   
        if cls not in instances:   
            instances[cls] = cls(*args, **kw)   
        return instances[cls]   
    return _singleton   


class IdGenerator(object):
    def __init__(self, start = 0):
        self.m_guid = start
        
    def setGuid(self, guid):
        if (guid > self.m_guid):
            self.m_guid = guid + 1
        
    def getGuid(self):
        self.m_guid += 1
        return self.m_guid

@singleton   
class ObjectIdGenerator(object):
    def __init__(self, start = 0):
        self.m_guid = start
        
    def setGuid(self, guid):
        if (guid > self.m_guid):
            self.m_guid = guid + 1
        
    def getGuid(self):
        self.m_guid += 1
        return self.m_guid
        
@singleton   
class MapIdGenerator(object):
    def __init__(self, start = 0):
        self.m_guid = start
        
    def setGuid(self, guid):
        if (guid > self.m_guid):
            self.m_guid = guid + 1
        
    def getGuid(self):
        self.m_guid += 1
        return self.m_guid
        
@singleton   
class GroupIdGenerator(object):
    def __init__(self, start = 0):
        self.m_guid = start
        
    def setGuid(self, guid):
        if (guid > self.m_guid):
            self.m_guid = guid + 1
        
    def getGuid(self):
        self.m_guid += 1
        return self.m_guid
    
if __name__ == '__main__':
    a = IdGenerator()
    print a.getGuid()
    b = IdGenerator()
    print b.getGuid()
    print a.getGuid()